<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>
    <p id="myParagraph">这是一个段落。</p>
    <button id="myButton">点击我</button>
</body>

<script>
    // 获取按钮和 <p> 标签的引用
    const button = document.getElementById('myButton');
    const paragraph = document.getElementById('myParagraph');

    // 随机数产生函数
    function random(number) {
        return Math.floor(Math.random() * (number + 1));
    }

    // 创建按钮的点击事件处理程序
    button.addEventListener('click', function () {
        // 修改 <p> 标签的颜色
        const rndCol = `rgb(${random(255)}, ${random(255)}, ${random(255)})`;
        paragraph.style.backgroundColor = rndCol;
    });

</script>

</html>